﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Screens
{
    /// <summary>
    /// show loading screen
    /// and load map stuff
    /// </summary>
    public static class LoadingMap
    {
        #region METHODS

        /// <summary>
        /// draw loading map screen
        /// </summary>
        public static void Draw()
        {
            try
            {
                Util.Cache.Draw(Util.Cache.GetTexture("LoadingScreen").Text2D, new int[] { 0, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height }, Color.White);
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }
        

        /// <summary>
        /// load map
        /// </summary>
        public static void LoadMap()
        {
            try
            {

                //player has chosen a map
                //then load chosen map config
                //load map cells
                Levels.LevelManager.LoadMap(); //map config
                Levels.LevelManager.LoadMapCells(); //map cells

                //loop thru all map cells and select the one, current one
                #region load or init mapc cell

                //check if there is map cell saved (if player played before) //TO BE IMPLEMENTED !!!!!!!!!!!

                //else, load first map cell [default map cell]
                Levels.LevelManager.CurrentMap.CurrentMapCell = Levels.LevelManager.CurrentMap.MapCells[0];

                //for (int i1 = 0; i1 < Levels.LevelManager.CurrentMap.MapCells.Count; i1++)
                //{
                //    if (Levels.LevelManager.CurrentMap.MapCells[i1].ID == Items[i].MapCellID)
                //    {
                //        //assign as current map cell
                //        Levels.LevelManager.CurrentMap.CurrentMapCell = Levels.LevelManager.CurrentMap.MapCells[i1];
                //        return true;
                //    }
                //}

                #endregion

             

                //change screen to level selector
                Util.Cache.SetCurrentScreen(Util.Cache.Screen.Game);

                Screens.MapSelector.MapSelectorItems = null;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        #endregion


    }
}
